---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend-{{ .Release.Name }}
  namespace: {{ .Release.Namespace }}
  labels:
    app: backend
    app.kubernetes.io/instance: "{{ .Release.Name }}"
    app.kubernetes.io/version: "{{ .Chart.AppVersion }}"
    app.kubernetes.io/managed-by: "{{ .Release.Service }}"
    helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
spec:
  replicas: {{ .Values.replicas }} 
  strategy:
    type: RollingUpdate
  selector:
    matchLabels:
      app: backend
  template:
    metadata:
      labels:
        app: backend
      annotations:
        prometheus.io/path: /metrics
        prometheus.io/port: "8081"
        prometheus.io/scrape: "true" 
    spec:
      containers:
        - name: backend
          image: "{{ .Values.image.repository }}:{{.Values.image.tag }}"
          resources:
            requests:
              cpu: {{ .Values.requests.cpu }}
            limits:
              cpu: {{ .Values.limits.cpu }}
          imagePullPolicy: Always
          ports:
            - name: backend
              containerPort: 8081
          livenessProbe:
            httpGet:
              path: /health
              port: 8081
            initialDelaySeconds: 15
            periodSeconds: 30
            timeoutSeconds: 1
            failureThreshold: 6
      imagePullSecrets:
        - name: docker-config-secret
